package com.swpu.project.controller;

import com.swpu.project.common.BaseResponse;
import com.swpu.project.mapper.DictionaryContentMapper;
import com.swpu.project.model.entity.DictionaryContent;
import com.swpu.project.service.IDataDictionaryService;
import com.swpu.project.service.IDictionaryContentService;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/dict")
public class DictionaryController {
    @Resource
    DictionaryContentMapper dictionaryContentMapper;
    @Resource
    IDataDictionaryService iDataDictionaryService;
  @Resource
    IDictionaryContentService iDictionaryContentService;


@GetMapping("/query")
@PreAuthorize("@verf.hasAuthorityFor('sys_manage')")
BaseResponse queryDict()
{
    return iDataDictionaryService.queryDict();
}



    @PostMapping("/query")
    @PreAuthorize("@verf.hasAuthorityFor('sys_manage')")
    BaseResponse addDict(@RequestBody List<DictionaryContent> dictionaryContents)
    {

        return BaseResponse.iFSuccess(iDictionaryContentService.saveBatch(dictionaryContents));
    }
    @PutMapping("/query")
    @PreAuthorize("@verf.hasAuthorityFor('sys_manage')")
    BaseResponse updateDict(@RequestBody List<DictionaryContent> dictionaryContents)
    {

        return BaseResponse.iFSuccess(iDictionaryContentService.updateBatchById(dictionaryContents));
    }
    @DeleteMapping("/query")
    @PreAuthorize("@verf.hasAuthorityFor('sys_manage')")
    BaseResponse deleteDict(@RequestBody List<DictionaryContent> dictionaryContents)
    {

        return BaseResponse.iFSuccess(iDictionaryContentService.removeBatchByIds(dictionaryContents));
    }






}
